@echo off
echo.
echo ==============================================
echo   YanXue AI Go OpenAI 问答功能测试
echo ==============================================
echo.

REM 设置环境变量（使用您提供的配置）
echo 正在设置AI配置环境变量...
set APP_NAME=example-service
set APP_VERSION=1.0.0
set APP_ENVIRONMENT=development
set SERVER_HOST=0.0.0.0
set SERVER_PORT=8081
set DATABASE_HOST=127.0.0.1
set DATABASE_PORT=3306
set DATABASE_USER=root
set DATABASE_PASSWORD=password
set DATABASE_NAME=yanxue_ai
set REDIS_HOST=127.0.0.1
set REDIS_PORT=6379
set REDIS_PASSWORD=redis_password
set AI_OPENAI_API_KEY=your_api_key_here
set AI_OPENAI_BASE_URL=https://api.example.com
set AI_OPENAI_MODEL=gpt-3.5-turbo
set LOG_LEVEL=info
set JWT_SECRET=example-jwt-secret-key-change-in-production

echo ✓ 环境变量设置完成
echo.

echo 显示AI配置信息:
echo   API Key: %AI_OPENAI_API_KEY%
echo   Base URL: %AI_OPENAI_BASE_URL%
echo   Model: %AI_OPENAI_MODEL%
echo   Agent服务端口: %SERVER_PORT%
echo.

echo 检查Go环境...
go version >nul 2>&1
if %errorlevel% neq 0 (
    echo ✗ 错误: Go未安装或不在PATH中
    pause
    exit /b 1
)
echo ✓ Go环境正常

echo.
echo 检查配置文件...
if not exist "configs\config.yml" (
    echo ✗ 错误: configs\config.yml 配置文件不存在
    pause
    exit /b 1
)
echo ✓ 配置文件存在

echo.
echo 更新Agent服务依赖...
cd services\agent
go mod tidy
if %errorlevel% neq 0 (
    echo ✗ 错误: Agent服务依赖更新失败
    cd ..\..
    pause
    exit /b 1
)
cd ..\..

echo ✓ 依赖更新完成

echo.
echo ==============================================
echo   配置验证完成，准备测试AI问答功能
echo ==============================================
echo.
echo 您可以选择测试方式:
echo   1. 启动Agent服务并测试问答API
echo   2. 仅验证配置（不启动服务）
echo   3. 查看API文档说明
echo.
set /p choice="请选择 (1-3): "

if "%choice%"=="1" (
    echo.
    echo 正在启动Agent服务...
    echo 服务将在 http://localhost:%SERVER_PORT% 启动
    echo.
    echo API端点说明:
    echo   健康检查: GET  http://localhost:%SERVER_PORT%/health
    echo   AI问答:   POST http://localhost:%SERVER_PORT%/api/v1/chat/ask
    echo   配置信息: GET  http://localhost:%SERVER_PORT%/api/v1/chat/config
    echo.
    echo 问答API请求示例:
    echo {
    echo   "question": "你好，请介绍一下你自己"
    echo }
    echo.
    echo 正在启动...
    cd services\agent
    go run cmd\main.go
) else if "%choice%"=="2" (
    echo.
    echo ✓ 配置验证完成！
    echo OpenAI配置已正确加载，支持以下功能:
    echo   - 从配置文件读取API Key和Base URL
    echo   - 从配置文件读取模型名称
    echo   - 支持AI问答接口调用
    echo   - 支持配置信息查询
) else if "%choice%"=="3" (
    echo.
    echo ==============================================
    echo   API使用说明
    echo ==============================================
    echo.
    echo 1. 启动Agent服务:
    echo    cd services\agent
    echo    go run cmd\main.go
    echo.
    echo 2. 测试API端点:
    echo.
    echo    健康检查:
    echo    curl http://localhost:8081/health
    echo.
    echo    AI问答:
    echo    curl -X POST http://localhost:8081/api/v1/chat/ask ^
    echo         -H "Content-Type: application/json" ^
    echo         -d "{\"question\": \"你好\"}"
    echo.
    echo    获取配置:
    echo    curl http://localhost:8081/api/v1/chat/config
    echo.
    echo 3. 响应格式:
    echo    问答响应: {"question": "...", "answer": "...", "model": "..."}
    echo    配置响应: {"model": "...", "available": true, "service": "OpenAI"}
) else (
    echo 无效选择，退出。
)

echo.
pause